import Vue from 'vue'
import Router from 'vue-router';

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

Vue.use(Router);
let router = new Router({
  routes: [
    {
      path: "/",
      name: "home",
      title: "首页",
      component: () => import('./views/home/index.vue'),
    },
    {
      path: "/test",
      name: "test",
      title: "测试",
      component: () => import('./views/test/index.vue'),
    },
		{
		  path: "/table",
		  name: "table",
		  title: "表格",
		  component: () => import('./views/table/index.vue'),
		},
		{
		  path: "/vxe-table",
		  name: "vxeTable",
		  title: "表格-vxe-table",
		  component: () => import('./views/table/vxe-table.vue'),
		},
    
  ]
})
router.beforeEach((to, from, next) => {
  // if (!sessionStorage.username) {
  //   if (to.name === 'login') {
  //     next();
  //   } else {
  //     next({ name: 'login' });
  //   }
  // } else {
  //   next();
  // }
  next();
});

router.afterEach(to => {
  if (to && to.meta && to.meta.title) {
    document.title = to.meta.title[1];
  }
});
export default router;
